package com.zero.logistics.mapper;

import com.zero.logistics.pojo.Customer;
import com.zero.logistics.pojo.CustomerExample;
import java.util.List;

import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

@CacheNamespace //开启Rediscache二级缓存机制
public interface CustomerMapper {
    @Delete({
        "delete from t_customer",
        "where customer_id = #{customerId,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long customerId);

    @Insert({
        "insert into t_customer (customer_id, customer_name, ",
        "phone, email, address, ",
        "gender, remark, ",
        "id_card, user_id, base_id)",
        "values (#{customerId,jdbcType=BIGINT}, #{customerName,jdbcType=VARCHAR}, ",
        "#{phone,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR}, ",
        "#{gender,jdbcType=INTEGER}, #{remark,jdbcType=VARCHAR}, ",
        "#{idCard,jdbcType=VARCHAR}, #{userId,jdbcType=BIGINT}, #{baseId,jdbcType=BIGINT})"
    })
    int insert(Customer record);

    @InsertProvider(type=CustomerSqlProvider.class, method="insertSelective")
    int insertSelective(Customer record);

    @SelectProvider(type=CustomerSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="customer_id", property="customerId", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="customer_name", property="customerName", jdbcType=JdbcType.VARCHAR),
        @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
        @Result(column="gender", property="gender", jdbcType=JdbcType.INTEGER),
        @Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR),
        @Result(column="id_card", property="idCard", jdbcType=JdbcType.VARCHAR),
        @Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT),
        @Result(column="base_id", property="baseId", jdbcType=JdbcType.BIGINT)
    })
    List<Customer> selectByExample(CustomerExample example);

    @Select({
        "select",
        "customer_id, customer_name, phone, email, address, gender, remark, id_card, ",
        "user_id, base_id",
        "from t_customer",
        "where customer_id = #{customerId,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="customer_id", property="customerId", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="customer_name", property="customerName", jdbcType=JdbcType.VARCHAR),
        @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
        @Result(column="gender", property="gender", jdbcType=JdbcType.INTEGER),
        @Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR),
        @Result(column="id_card", property="idCard", jdbcType=JdbcType.VARCHAR),
        @Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT),
        @Result(column="base_id", property="baseId", jdbcType=JdbcType.BIGINT)
    })
    Customer selectByPrimaryKey(Long customerId);

    @UpdateProvider(type=CustomerSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Customer record);

    @Update({
        "update t_customer",
        "set customer_name = #{customerName,jdbcType=VARCHAR},",
          "phone = #{phone,jdbcType=VARCHAR},",
          "email = #{email,jdbcType=VARCHAR},",
          "address = #{address,jdbcType=VARCHAR},",
          "gender = #{gender,jdbcType=INTEGER},",
          "remark = #{remark,jdbcType=VARCHAR},",
          "id_card = #{idCard,jdbcType=VARCHAR},",
          "user_id = #{userId,jdbcType=BIGINT},",
          "base_id = #{baseId,jdbcType=BIGINT}",
        "where customer_id = #{customerId,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Customer record);

    @DeleteProvider(type=CustomerSqlProvider.class, method="deleteByIds")
	int deleteByIds(@Param("ids")String[] ids);
}